function SinglePollItem(obj)
{
  this.obj = obj;

  this.getVoteButton = function()
  {
    var name = this.obj['name'];
    var id = wave.getViewer().getId();

    var votedFor = getVote(id);

    var button = newElement("button", {className: 'textVoteButton'});
	  if( votedFor == name )
    {
      button.title = "Unvote this option";
      button.innerHTML = "Unvote";
      $(button).bind('click', {name:name}, function(ev) {
        setVote(id, null);
          });
    }
    else
    {
      button.title = "Vote for this option";
      button.innerHTML = "Vote"
        $(button).bind('click', {name:name}, function(ev) {
          setVote(id, ev.data.name);
        });
    }

    return button;
  }

  this.getNumVotes = function()
  {
    return this.getVoters().length;
  }

  this.getVoters = function()
  {
    var name = this.obj['name'];
    return jQuery.grep(wave.getParticipants(), function(p) {
        return (getVote(p.getId()) == name);
        });
  }
}

function setVote(id, value)
{
  var delta = {};
  delta[id] = value;
  wave.getState().submitDelta(delta);
}

function getVote(id)
{
  return wave.getState().get(id);
}

function renderPoll(state)
{
  renderTable(state, SinglePollItem);
}

